﻿

namespace Mulala.Cavan.Presentation.Mvc.Controller
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Presentation.Seedwork;
    using Mulala.Cavan.Domain.MainBoundedContext.CorporationModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Presentation.Mvc.ViewModel;
    using Mulala.Cavan.Application.MainBoundedContext.CorporationModule;
    using System.Web.Mvc;
    using Mulala.Cavan.Application.MainBoundedContext.AttachmentModule;
    using Mulala.Cavan.Domain.MainBoundedContext.Setting;

    public class CorporationCommentController : EntityController<CorporationComment, CorporationCommentSearch, ICorporationCommentViewModel, ICorporationCommentAppService>, ICorporationCommentController
    {
        private IAttachmentAppService AttachmentAppService { get; set; }

        public override string ControllerName
        {
            get { return ControllerConst.CORPORATIONCOMMENT; }
        }

        public override bool UseDenied
        {
            get { return false; }
        }

        [ActionName("topcomment")]
        [ChildActionOnly]
        public ActionResult GetCorporationComments(int id)
        {
            IDictionary<string, bool> orderBy = new Dictionary<string, bool>();
            orderBy.Add("CreateTime", true);

            CorporationCommentSearch corporationCommentSearch = CorporationCommentSearchFactory.CreateCorporationCommentSearch(id, orderBy, 1, Project.Settings.TopCorporationCommentAmount);

            long total = 0;
            IList<CorporationComment> corporationComments = this.AppService.GetBySearch(corporationCommentSearch, out total).ToList();
            ICorporationCommentsViewModel corporationCommentsViewModel = ModelFactory.CreateModel<ICorporationCommentsViewModel>();
            IList<ICorporationCommentViewModel> corporationCommentViewModels = CorporationCommentViewModelConverter.Convert(corporationComments);
            corporationCommentsViewModel.CorporationComments = corporationCommentViewModels;

            return PartialView("~/Views/CorporationComment/_corporationCommentPartial.cshtml", corporationCommentsViewModel);
        }
    }
}
